← Back

OBJECT-ORIENTED PROGRAMMING (OOP) — SIMPLE NOTE

This note explains OOP in simple language.

You will learn:

  1. why good code is more than code that only works
  2. what procedural programming is
  3. what object-oriented programming is
  4. what a class is
  5. what an instance is
  6. what an interface is

1. Good code vs bad code

At first, it may seem that the difference is simple:

But in real projects, that is not enough.

A modern product can have a very large codebase. So code must not only work, it must also be easy to support, improve, and grow.

Important qualities of good code are:

Diagram 1. Good code is more than “it works”

Good code
│
├─ works correctly
├─ is reliable
├─ is scalable
├─ is adaptable
└─ is cost-effective

A program that works today but is hard to change tomorrow is not really good code.

2. Why programming paradigms matter

To write better code, developers use programming paradigms.

A programming paradigm is a general way of organizing code.

In this topic, the two important paradigms are:

Diagram 2. Two approaches

Programming paradigms
│
├─ Procedural programming
└─ Object-oriented programming

3. Procedural programming

Procedural programming is a style where a program is built as a set of functions that work with data.

The main ideas are:

Diagram 3. Procedural programming idea

Data
↓
Functions process the data
↓
Result

In procedural programming, data and functions are often separate.

4. Procedural programming example

const baseSalary = 30000;
const overtime = 10;
const rate = 20;

const getWage = (baseSalary, overtime, rate) => {
  return baseSalary + overtime * rate;
};

getWage(baseSalary, overtime, rate);

This is a procedural style because:

Diagram 4. Procedural example structure

baseSalary
overtime
rate
↓
getWage(...)
↓
result

The function needs outside values to work.

5. Strength of procedural programming

Procedural programming is:

It is good for simple programs.

6. Weakness of procedural programming

As a program becomes more complex, this style can become weaker because the connection between:

becomes less clear.

Diagram 5. Problem in procedural programming

Data       Function
baseSalary getWage()
overtime
rate

They work together,
but they are stored separately

In large programs, this can make the code harder to maintain.

7. Object-oriented programming (OOP)

Object-oriented programming, or OOP, is a style where programs are organized as a collection of objects.

An object represents a real or abstract thing, for example:

Each object contains:

Diagram 6. OOP idea

Object
│
├─ properties (data)
└─ methods (actions)

In OOP, data and the functions that work with that data are grouped together.

8. OOP example

Let us rewrite the wage example in OOP style:

const employee = {
  baseSalary: 30000,
  overtime: 10,
  rate: 20,
  getWage() {
    return this.baseSalary + this.overtime * this.rate;
  },
};

employee.getWage();

Why this is OOP

Now:

Diagram 7. OOP example structure

employee
│
├─ baseSalary: 30000
├─ overtime: 10
├─ rate: 20
└─ getWage()

This is more organized than storing everything separately.

9. Why OOP is useful

OOP helps because it:

Diagram 8. Why OOP helps

OOP
↓
better structure
↓
easier maintenance
↓
better for complex programs

10. What is a class?

A class is a blueprint or template for creating objects. It describes:

The source text explains this through a car example. Imagine designing a car before it is built. You decide:

That design is like a class.

Diagram 9. Class = blueprint

Class
↓
template / blueprint
↓
used to create objects

A class is not one real object yet. It is the general model.

11. Car example for class

If we design a car class, we describe:

Properties

Methods

Diagram 10. Car class

Car class
│
├─ properties
│  ├─ engine
│  ├─ wheels
│  ├─ headlights
│  └─ fuel tank
│
└─ methods
   ├─ openDoor()
   ├─ startEngine()
   ├─ speedUp()
   └─ slowDown()

12. What is an instance?

An instance is a real object created from a class.

If the class is the blueprint of a car, then an instance is one real car made from that blueprint.

The class gives the structure.

The instance gives the real values.

Diagram 11. Class vs instance

Class
↓
blueprint of a car

Instance
↓
one real car created from that blueprint

The class is general. The instance is concrete.

13. Easy way to remember class and instance

Class    = model
Instance = real object made from the model

Or:

Class    = drawing
Instance = built object

14. Why instances are unique

Even if many objects are created from the same class, they are still different.

For example, cars from the same model can still have different:

Diagram 12. Same class, many unique objects

One class
↓
Car 1
Car 2
Car 3

Same structure
Different values

That is why classes are useful: one blueprint can create many real objects.

15. What is an interface?

An interface is the set of properties and methods of a class that are available for use when working with an instance.

In simple words:

The interface is what you can use.

The text compares this to a car dashboard.

When you sit in a car, you interact with:

That is similar to using the interface of a class.

Diagram 13. Interface idea

Class
↓
available controls
↓
interface

The interface shows what actions are possible.

16. Car interface example

In the car example, the interface allows actions like:

Diagram 14. Car dashboard = interface

Dashboard controls
│
├─ brake
├─ speed up
├─ turn
├─ change gear
└─ switch lights on

The driver does not need to know every inner detail of the engine.

The driver just uses the interface.

17. Good interface balance

The source text explains that when designing an interface, you need balance between:

If the interface is too simple:

If the interface is too flexible:

Diagram 15. Interface balance

Too simple
↓
easy to use
but limited

Too complex
↓
powerful
but harder to use

A good interface should be powerful enough, but still easy to understand.

18. Procedural programming vs OOP

Now we can compare them clearly.

Procedural programming

OOP

Diagram 16. Procedural vs OOP

Procedural
↓
separate data + separate functions

OOP
↓
object = data + methods together

19. Easy memory rules

Procedural = functions work on separate data
OOP        = objects keep data and behavior together

Class      = blueprint
Instance   = real object
Interface  = available controls

20. Quick summary

21. Final conclusion

OOP is important because it helps organize code in a way that is easier to build, understand, and maintain.

If you understand these four ideas:

Object = data + methods
Class = blueprint
Instance = real object
Interface = available controls

then you already understand the basic foundation of object-oriented programming.

← Back